<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>结算页</title>

    <link rel="stylesheet" type="text/css" href="/static/order/css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="/static/order/css/pages-getOrderInfo.css" />
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script th:inline="javascript">
        //0. 得到所有的用户地址列表
        let addressList = [[${addressList}]];
        let cartList = [[${cartList}]];
        //1. 窗体加载时，显示默认地址
        let flag = true;
        $(function(){
            //1.1 得到默认地址
            getDefaultAddr();

            //1.2 计算总金额
            calcTotalMoney();
        })
        //1. 用户选择
        function userSelect(addr){
            console.log("addr:",addr);
            //1.1 移除所有的.selected类
            if(!flag){
                $(".con").removeClass("selected");
            }

            //1.2 为下面的地址设置值
            let info = "寄送至:";
            info += addr.address + " 收货人：" + addr.contact + " " + addr.mobile;
            $("#myAddr").html(info);

            //1.3 为表单隐藏域赋值
            $("#receiverAreaName").val(addr.address);
            $("#receiverMobile").val(addr.mobile);
            $("#receiver").val(addr.contact);


        }

        //2. 得到默认地址
        function  getDefaultAddr() {
            let addr = "";
            addressList.forEach(address=>{
                if(address.isDefault == '1'){
                    addr = address;
                }
            })
            userSelect(addr);
            selectType(1)
            flag = false;
        }

        //3. 计算总金额
        function calcTotalMoney() {
            //3.1 定义总数量与总金额
            let num = 0;
            let money = 0;
            //3.2 累加总数量与总金额
            cartList.forEach(cart=>{
                cart.orderItemList.forEach(item=>{
                    num += parseInt(item.num);		//累加数量
                    money += parseFloat(item.totalFee.toFixed(2));	//累加总金额
                })
            })
            //3.3 为总数量及总金额变量赋值
            $("#number").html(num);
            $("#allprice").html("￥"+money);
            $("#price").html("￥"+money);
        }

        //4. 支付类型
        function selectType(type){
            $("#paymentType").val(type);
        }

        //5. 提交订单
        function submitOrder() {
            let info = $("#form1").serialize();
            console.log(info);
            document.forms[0].submit();
        }
    </script>
</head>

<body>
<form action="/order/add" th:action="@{/order/add}" method="post" id="form1">
    <input type="hidden" name="receiverAreaName" id="receiverAreaName">
    <input type="hidden" name="receiverMobile" id="receiverMobile">
    <input type="hidden" name="receiver" id="receiver">
    <input type="hidden" name="paymentType" id="paymentType">
</form>
<!--head-->
<div class="top">
    <div class="py-container">
        <div class="shortcut">
            <ul class="fl">
                <li class="f-item">泽易购欢迎您！</li>
                <li class="f-item">请登录　<span><a href="#">免费注册</a></span></li>
            </ul>
            <ul class="fr">
                <li class="f-item">我的订单</li>
                <li class="f-item space"></li>
                <li class="f-item">我的泽易购</li>
                <li class="f-item space"></li>
                <li class="f-item">泽易购会员</li>
                <li class="f-item space"></li>
                <li class="f-item">企业采购</li>
                <li class="f-item space"></li>
                <li class="f-item">关注泽易购</li>
                <li class="f-item space"></li>
                <li class="f-item">客户服务</li>
                <li class="f-item space"></li>
                <li class="f-item">网站导航</li>
            </ul>
        </div>
    </div>
</div>
<div class="cart py-container">
    <!--logoArea-->
    <div class="logoArea">
        <div class="fl logo"><span class="title">结算页</span></div>
        <div class="fr search">
            <form class="sui-form form-inline">
                <div class="input-append">
                    <input type="text" class="input-error input-xxlarge" placeholder="泽易购自营" />
                    <button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
                </div>
            </form>
        </div>
    </div>
    <!--主内容-->
    <div class="checkout py-container">
        <div class="checkout-tit">
            <h4 class="tit-txt">填写并核对订单信息</h4>
        </div>
        <div class="checkout-steps">
            <!--收件人信息-->
            <div class="step-tit">
                <h5>收件人信息<span><a data-toggle="modal" data-target=".edit" data-keyboard="false" class="newadd">新增收货地址</a></span></h5>
            </div>
            <div class="step-cont">
                <div class="addressInfo">
                    <ul class="addr-detail">
                        <li class="addr-item">

                            <div th:each="addr : ${addressList}">
                                <div th:class="${addr.isDefault == '1' ? 'con name selected' : 'con name'} ">
                                    <a href="javascript:;" th:onclick="userSelect([[${addr}]])">[[${addr.contact}]]<span title="点击取消选择">&nbsp;</a>
                                </div>
                                <div class="con address">[[${addr.contact}]] [[${addr.address}]] <span>[[${addr.mobile}]]</span>
                                    <span class="base" th:if="${addr.isDefault == '1'}">默认地址</span>
                                    <span class="edittext"><a data-toggle="modal" data-target=".edit" data-keyboard="false" >编辑</a>&nbsp;&nbsp;<a href="javascript:;">删除</a></span>
                                </div>
                                <div class="clearfix"></div>
                            </div>

                        </li>


                    </ul>
                    <!--添加地址-->
                    <div  tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade edit">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×</button>
                                    <h4 id="myModalLabel" class="modal-title">添加收货地址</h4>
                                </div>
                                <div class="modal-body">
                                    <form action="" class="sui-form form-horizontal">
                                        <div class="control-group">
                                            <label class="control-label">收货人：</label>
                                            <div class="controls">
                                                <input type="text" class="input-medium">
                                            </div>
                                        </div>

                                        <div class="control-group">
                                            <label class="control-label">详细地址：</label>
                                            <div class="controls">
                                                <input type="text" class="input-large">
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label">联系电话：</label>
                                            <div class="controls">
                                                <input type="text" class="input-medium">
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label">邮箱：</label>
                                            <div class="controls">
                                                <input type="text" class="input-medium">
                                            </div>
                                        </div>
                                        <div class="control-group">
                                            <label class="control-label">地址别名：</label>
                                            <div class="controls">
                                                <input type="text" class="input-medium">
                                            </div>
                                            <div class="othername">
                                                建议填写常用地址：<a href="#" class="sui-btn btn-default">家里</a>　<a href="#" class="sui-btn btn-default">父母家</a>　<a href="#" class="sui-btn btn-default">公司</a>
                                            </div>
                                        </div>

                                    </form>


                                </div>
                                <div class="modal-footer">
                                    <button type="button" data-ok="modal" class="sui-btn btn-primary btn-large">确定</button>
                                    <button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--确认地址-->
                </div>
                <div class="hr"></div>

            </div>
            <div class="hr"></div>
            <!--支付和送货-->
            <div class="payshipInfo">
                <div class="step-tit">
                    <h5>支付方式</h5>
                </div>
                <div class="step-cont">
                    <ul class="payType">
                        <li class="selected" onclick="selectType(1)">微信付款<span title="点击取消选择"></span></li>
                        <li  onclick="selectType(2)">货到付款<span title="点击取消选择"></span></li>
                    </ul>
                </div>
                <div class="hr"></div>
                <div class="step-tit">
                    <h5>送货清单</h5>
                </div>
                <div class="step-cont">
                    <ul class="send-detail" th:each="cart: ${cartList}">
                        <li >
                            【[[${cart.sellerName}]]】
                            <div class="sendGoods" th:each="item : ${cart.orderItemList}">

                                <ul class="yui3-g">
                                    <li class="yui3-u-1-6">
                                        <span><img th:src="${item.picPath}"/></span>
                                    </li>
                                    <li class="yui3-u-7-12">
                                        <div class="desc">[[${item.title}]]</div>
                                        <div class="seven">7天无理由退货</div>
                                    </li>
                                    <li class="yui3-u-1-12">
                                        <div class="price">￥[[${item.price}]]</div>
                                    </li>
                                    <li class="yui3-u-1-12">
                                        <div class="num">X[[${item.num}]]</div>
                                    </li>
                                    <li class="yui3-u-1-12">
                                        <div class="exit">有货</div>
                                    </li>
                                </ul>

                            </div>

                        </li>

                    </ul>
                </div>
                <div class="hr"></div>
            </div>
            <div class="linkInfo">
                <div class="step-tit">
                    <h5>发票信息</h5>
                </div>
                <div class="step-cont">
                    <span>普通发票（电子）</span>
                    <span>个人</span>
                    <span>明细</span>
                </div>
            </div>
            <div class="cardInfo">
                <div class="step-tit">
                    <h5>使用优惠/抵用</h5>
                </div>
            </div>
        </div>
    </div>
    <div class="order-summary">
        <div class="static fr">
            <div class="list">
                <span><i class="number" id="number">xxx</i>件商品，总商品金额</span>
                <em class="allprice" id="allprice">¥5399.00</em>
            </div>
            <div class="list">
                <span>返现：</span>
                <em class="money">0.00</em>
            </div>
            <div class="list">
                <span>运费：</span>
                <em class="transport">0.00</em>
            </div>
        </div>
    </div>
    <div class="clearfix trade">
        <div class="fc-price">应付金额:　<span class="price" id="price">¥5399.00</span></div>
        <div class="fc-receiverInfo" id="myAddr">寄送至:北京市海淀区三环内 中关村软件园9号楼 收货人：某某某 159****3201</div>
    </div>
    <div class="submit">
        <a class="sui-btn btn-danger btn-xlarge" href="javascript:;" onclick="submitOrder()">提交订单</a>
    </div>
</div>
<!-- 底部栏位 -->
<!--页面底部-->
<div class="clearfix footer">
    <div class="py-container">
        <div class="footlink">
            <div class="Mod-service">
                <ul class="Mod-Service-list">
                    <li class="grid-service-item intro  intro1">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item  intro intro2">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item intro  intro3">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item  intro intro4">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                    <li class="grid-service-item intro intro5">

                        <i class="serivce-item fl"></i>
                        <div class="service-text">
                            <h4>正品保障</h4>
                            <p>正品保障，提供发票</p>
                        </div>

                    </li>
                </ul>
            </div>
            <div class="clearfix Mod-list">
                <div class="yui3-g">
                    <div class="yui3-u-1-6">
                        <h4>购物指南</h4>
                        <ul class="unstyled">
                            <li>购物流程</li>
                            <li>会员介绍</li>
                            <li>生活旅行/团购</li>
                            <li>常见问题</li>
                            <li>购物指南</li>
                        </ul>

                    </div>
                    <div class="yui3-u-1-6">
                        <h4>配送方式</h4>
                        <ul class="unstyled">
                            <li>上门自提</li>
                            <li>211限时达</li>
                            <li>配送服务查询</li>
                            <li>配送费收取标准</li>
                            <li>海外配送</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>支付方式</h4>
                        <ul class="unstyled">
                            <li>货到付款</li>
                            <li>在线支付</li>
                            <li>分期付款</li>
                            <li>邮局汇款</li>
                            <li>公司转账</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>售后服务</h4>
                        <ul class="unstyled">
                            <li>售后政策</li>
                            <li>价格保护</li>
                            <li>退款说明</li>
                            <li>返修/退换货</li>
                            <li>取消订单</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>特色服务</h4>
                        <ul class="unstyled">
                            <li>夺宝岛</li>
                            <li>DIY装机</li>
                            <li>延保服务</li>
                            <li>泽易购E卡</li>
                            <li>泽易购通信</li>
                        </ul>
                    </div>
                    <div class="yui3-u-1-6">
                        <h4>帮助中心</h4>
                        <img src="/static/order/img/wx_cz.jpg">
                    </div>
                </div>
            </div>
            <div class="Mod-copyright">
                <ul class="helpLink">
                    <li>关于我们<span class="space"></span></li>
                    <li>联系我们<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>商家入驻<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们<span class="space"></span></li>
                    <li>营销中心<span class="space"></span></li>
                    <li>友情链接<span class="space"></span></li>
                    <li>关于我们</li>
                </ul>
                <p>地址：深圳市大冲国际</p>

            </div>
        </div>
    </div>
</div>
<!--页面底部END-->

<script type="text/javascript" src="/static/order/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/static/order/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="/static/order/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="/static/order/components/ui-modules/nav/nav-portal-top.js"></script>
<script type="text/javascript" src="/static/order/js/pages/getOrderInfo.js"></script>
</body>

</html>